package com.straw.hat.jdk.troubleshooting.skills;

/**
 * @author jianshan@byai.com
 * @date 2020/12/2 10:03 AM
 * describe:
 */
public class JstackTroubleshootingSkills {




    private  static byte [] monitor = new byte[0];

    public static void main(String[] args) {
        Runnable task = () -> {
            synchronized (monitor)
            {
                long begin = System.currentTimeMillis();

                // 让线程运行5分钟,会一直持有object的监视器
                while ((System.currentTimeMillis() - begin) <= 5 * 60 * 1000)
                {
                    try
                    {
                        // 进入等待的同时,会进入释放监视器
                        monitor.wait();
                    } catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        };
        new Thread(task, "t1").start();
        new Thread(task, "t2").start();
    }

}
